package com.dd.shop4j.website.member.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.dd.shop4j.common.utils.HttpRequestUtils;
import com.dd.shop4j.member.model.MemberInfo;

/**
 * 会员安全util类
 * @ClassName: MemberSecurityUtils
 * @Description: TODO
 * @author 唐小恕
 * @date 2013年12月19日 下午9:57:26
 *
 */
public class MemberSecurityUtils {

	/**
	 * 得到当前用户
	 * @return
	 */
	public static MemberInfo getCurMember() {
		HttpServletRequest request = HttpRequestUtils.getRequest();
		HttpSession session = request.getSession();
		return (MemberInfo) session.getAttribute(UserSecurityInterceptor.loginSessionToken);
	}
	
	/**
	 * 获得当前用户的id 
	 * @return 用户id，没有登录返回-1
	 */
	public static int getCurMemberId() {
		MemberInfo member = getCurMember();
		if (member != null) {
			return member.getId();
		}
		return -1;
	}
	
}
